<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <script src="https://cdn.staticfile.net/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
  <button id="btnGET">GET</button>
  <button id="btnPOST">POST</button>
  <button id="btnDELETE">DELETE</button>
  <button id="btnJSONP">JSONP</button>

  <script>
    $(function () {
      //1.测试get接口
      $('#btnGET').on('click', function() {
        $.ajax({
          type: 'GET',
          url: 'http://127.0.0.1/api/get',
          data: {name: 'zs', age: 20},
          success: function(res) {
            console.log(res)
          },
        })
      })
      //2.测试post接口
      $('#btnPOST').on('click', function() {
        $.ajax({
          type: 'POST',
          url: 'http://127.0.0.1/api/post',
          data: {name: 'zs', age: 20},
          success: function(res) {
            console.log(res)
          },
        })
      })

      //为删除按钮绑定点击事件处理函数
      $('#btnDELETE').on('click', function () {
        $.ajax({
          type: 'DELETE',
          url: 'http://127.0.0.1/api/delete',
          success: function (res) {
            console.log(res)
            
          }
        })
      })
    })

    //为JSONP按钮绑定点击事件函数
    $('#btnJSONP').on('click', function() {
      $.ajax({
        type: 'GET',
        url: 'http://127.0.0.1/api/jsonp',
        dataType: 'jsonp',
        success: function (res) {
            console.log(res)
            
          }
      })
    })

  </script>
</body>
</html>